import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
import { useI18n } from '@/hooks/basic/useI18n'

export const useMessage = () => {
  const { t } = useI18n()

  return {
    // 通知提示
    notify(content: string, config = {}) {
      ElNotification.info({ message: content, customClass: 'is-info', ...config })
    },
    // 成功通知
    notifySuccess(content: string, config = {}) {
      ElNotification.success({ message: content, customClass: 'is-success', ...config })
    },
    // 警告通知
    notifyWarning(content: string, config = {}) {
      ElNotification.warning({ message: content, customClass: 'is-warning', ...config })
    },
    // 错误通知
    notifyError(content: string, config = {}) {
      ElNotification.error({ message: content, customClass: 'is-error', ...config })
    },
    // 确认窗体
    confirm(content: string, tip?: string, config = {}) {
      return ElMessageBox.confirm(content, tip ? tip : t('common.tips.confirmTitle'), {
        confirmButtonText: t('operate.confirm'),
        cancelButtonText: t('operate.cancel'),
        type: 'warning',
        ...config
      })
    },
    // 警告窗体
    confirmWarning(content?: string, tip?: string, config = {}) {
      return ElMessageBox.confirm(content, tip ? tip : t('common.tips.confirmTitle'), {
          confirmButtonText: t('operate.confirm'),
          confirmButtonClass: 'el-button--warning',
          cancelButtonText: t('operate.cancel'),
          type: 'warning',
          ...config
        }
      )
    },
    // 删除窗体
    confirmError(content?: string, tip?: string, config = {}) {
      return ElMessageBox.confirm(
        content ? content : t('operate.deletePrompt.selectedMsg'),
        tip ? tip : t('common.tips.confirmTitle'),
        {
          confirmButtonText: t('operate.confirm'),
          confirmButtonClass: 'el-button--danger',
          cancelButtonText: t('operate.cancel'),
          type: 'error',
          ...config
        }
      )
    },
  }
}
